<?php
class Bestmagento_BmProducts_Block_Product_ListNew extends Mage_Catalog_Block_Product_List{

    protected function _getProductCollection()
    {
        if (is_null($this->_productCollection)) {
            $start_date = Mage::app()->getLocale()->date()->subDay(14)->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
            $this->_productCollection  = Mage::getResourceModel('catalog/product_collection');
             $this->_productCollection->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds());

         $this->_productCollection = $this->_addProductAttributesAndPrices( $this->_productCollection);
            $this->_productCollection 
                ->addStoreFilter()->addAttributeToSelect('created_date')
                ->addAttributeToFilter('created_date', array('date' => true, 'from' => $start_date))
                ;
        }
        return $this->_productCollection;

    }
    /**
     * Need use as _prepareLayout - but problem in declaring collection from
     * another block (was problem with search result)
     */
    protected function _beforeToHtml()
    {
        /*$toolbar = $this->getLayout()->createBlock('catalog/product_list_toolbar', microtime());
        if ($toolbarTemplate = $this->getToolbarTemplate()) {
            $toolbar->setTemplate($toolbarTemplate);
        }*/
        $toolbar = $this->getToolbarBlock();

        // called prepare sortable parameters
        $collection = $this->_getProductCollection();
        //Mage::log($this->getAvailableOrders());
        // use sortable parameters
        if ($orders = $this->getAvailableOrders()) {
          
            $toolbar->setAvailableOrders($orders);
        }
        if ($sort = $this->getSortBy()) {
            $toolbar->setDefaultOrder($sort);
        }
        if ($dir = $this->getDefaultDirection()) {
            $toolbar->setDefaultDirection($dir);
        }
        if ($modes = $this->getModes()) {
            $toolbar->setModes($modes);
        }

        // set collection to toolbar and apply sort
        $toolbar->setCollection($collection);

        $this->setChild('toolbar', $toolbar);
        Mage::dispatchEvent('catalog_block_product_list_collection', array(
            'collection' => $this->_getProductCollection()
        ));

        $this->_getProductCollection()->load();
        Mage::getModel('review/review')->appendSummary($this->_getProductCollection());
        return parent::_beforeToHtml();
    }
    public function getAvailableOrders(){
    
     return array('created_date'=>'Created Date','price'=>'Price','name'=>'Name');
    
    }
    public function getDefaultDirection(){
    
      return 'desc';
    }

}  
